<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>镜像站@Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/admin/plugin/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <script type="text/javascript" src="/admin/js-css/js/mx1.0.js?v=1.3"></script>

    <style type="text/css">
        .layui-table-click {
            background-color:cadetblue !important;
            color:white;
        }
    </style>

</head>
<body>

<!--
<div class="layui-btn-group" style="display: none;">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_add()">增加</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_update()">编辑</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_delete()">删除</button>
</div>
-->

<table id="demo" lay-filter="test"></table>


<script src="/admin/plugin/layui/dist/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>


    var table = null;
    var $ = null;
    layui.use(['table','jquery'], function(){
        table = layui.table;
        $ = layui.$ //重点处

        //执行渲染
        table.render({
            id:"idTest",
            elem: '#demo' //指定原始表格元素选择器（推荐id选择器）
            ,height: "full-50" //容器高度
            ,cols:[[{checkbox: true},{field:"id",title:"字段id"},
                {field:"show_name",title: "字段中文名称"}
                ,{field: "col_name",title:"字段名称"}
                ,{field: "msg",title:"说明"}
                ,{field: "col_type",title:"字段类型"}
                ,{field: "zygl_id",title:"表id"}
                ,{field: "is_input",title:"录入是否显示"}
                ,{field: "is_list",title:"列表是否显示"}
                ,{field: "is_search",title:"是否默认查询"}
                ,{field: "length",title:"字段长度"}
                ,{field: "show_order",title:"排序号"}]] //设置表头
            ,url:wwwurl+"/admin/api/FieldManagementController/list_input"
            ,where:{searchInputDtos:{"zygl_id":{key:"zygl_id",type:"6",value:top.data.treeObj.zygl_id}}}
            ,contentType: 'application/json'
            ,method:"post"
            ,page:true
            ,limit:50
            ,toolbar: '.layui-btn-group'
            ,request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            headers: {
                token:localStorage.getItem("token")
            }
            ,parseData:function(res){
                return {
                    "code": "0", //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
            //,…… //更多参数参考右侧目录：基本参数选项
        });

        //监听行单击事件
        table.on('row(test)', function (obj) {
            //动态添加背景色
            if (obj.tr.hasClass('layui-table-click')) {
                obj.tr.removeClass('layui-table-click');    //删除背景色和
                obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
            } else {
                obj.tr.addClass('layui-table-click');
                obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
            }

            var index = obj.tr.data('index');
            var tableData = table.cache.idTest;//menu 是表格id
            var trHasClass = obj.tr.hasClass('layui-table-click');

            //循环判断class,选中checkbox
            layui.each(tableData, function (i, item) {
                if (trHasClass == true) {
                    if (index == i) {
                        item.LAY_CHECKED = true;
                    }
                } else {
                    if (index == i) {
                        item.LAY_CHECKED = false;
                    }
                }
            });
        });
    });


    //Demo
    layui.use('form', function(){
        form = layui.form;
        //监听提交
        form.on('submit(*)', function(data){
            console.log("1111");
        });
    });

    var ids = [];

    function getData() {
        return {ids:""+ids};
    }


    function verification() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        console.log(checkStatus.data.length);
        if(checkStatus.data.length < 1){
            top.alert("至少选择选择一条记录进行提交");
            return;
        }
        ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        return true;
    }


    function setData(data) {

    }

</script>

</body>
</html>
